﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using BesAsm.MasterData.Entities;
using BesAsm.MasterData.Data;

#endregion

namespace BesAsm.MasterData.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="DscZingerProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class DscZingerProviderBaseCore : EntityProviderBase<BesAsm.MasterData.Entities.DscZinger, BesAsm.MasterData.Entities.DscZingerKey>
	{		
		#region Get from Many To Many Relationship Functions
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, BesAsm.MasterData.Entities.DscZingerKey key)
		{
			return Delete(transactionManager, key.DscZingerId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="_dscZingerId">Primary key, DSC zinger ID. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.Int32 _dscZingerId)
		{
			return Delete(null, _dscZingerId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_dscZingerId">Primary key, DSC zinger ID. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.Int32 _dscZingerId);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DSC_ZINGERS_DSCS key.
		///		FK_DSC_ZINGERS_DSCS Description: 
		/// </summary>
		/// <param name="_dscId">Foreign key to DSCS</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.DscZinger objects.</returns>
		public TList<DscZinger> GetByDscId(System.Int32? _dscId)
		{
			int count = -1;
			return GetByDscId(_dscId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DSC_ZINGERS_DSCS key.
		///		FK_DSC_ZINGERS_DSCS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_dscId">Foreign key to DSCS</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.DscZinger objects.</returns>
		/// <remarks></remarks>
		public TList<DscZinger> GetByDscId(TransactionManager transactionManager, System.Int32? _dscId)
		{
			int count = -1;
			return GetByDscId(transactionManager, _dscId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_DSC_ZINGERS_DSCS key.
		///		FK_DSC_ZINGERS_DSCS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_dscId">Foreign key to DSCS</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.DscZinger objects.</returns>
		public TList<DscZinger> GetByDscId(TransactionManager transactionManager, System.Int32? _dscId, int start, int pageLength)
		{
			int count = -1;
			return GetByDscId(transactionManager, _dscId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DSC_ZINGERS_DSCS key.
		///		fkDscZingersDscs Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_dscId">Foreign key to DSCS</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.DscZinger objects.</returns>
		public TList<DscZinger> GetByDscId(System.Int32? _dscId, int start, int pageLength)
		{
			int count =  -1;
			return GetByDscId(null, _dscId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DSC_ZINGERS_DSCS key.
		///		fkDscZingersDscs Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_dscId">Foreign key to DSCS</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.DscZinger objects.</returns>
		public TList<DscZinger> GetByDscId(System.Int32? _dscId, int start, int pageLength,out int count)
		{
			return GetByDscId(null, _dscId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DSC_ZINGERS_DSCS key.
		///		FK_DSC_ZINGERS_DSCS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_dscId">Foreign key to DSCS</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.DscZinger objects.</returns>
		public abstract TList<DscZinger> GetByDscId(TransactionManager transactionManager, System.Int32? _dscId, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DSC_ZINGERS_LINKS key.
		///		FK_DSC_ZINGERS_LINKS Description: 
		/// </summary>
		/// <param name="_linkId">Foreign key to LINKS</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.DscZinger objects.</returns>
		public TList<DscZinger> GetByLinkId(System.Int32 _linkId)
		{
			int count = -1;
			return GetByLinkId(_linkId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DSC_ZINGERS_LINKS key.
		///		FK_DSC_ZINGERS_LINKS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_linkId">Foreign key to LINKS</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.DscZinger objects.</returns>
		/// <remarks></remarks>
		public TList<DscZinger> GetByLinkId(TransactionManager transactionManager, System.Int32 _linkId)
		{
			int count = -1;
			return GetByLinkId(transactionManager, _linkId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_DSC_ZINGERS_LINKS key.
		///		FK_DSC_ZINGERS_LINKS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_linkId">Foreign key to LINKS</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.DscZinger objects.</returns>
		public TList<DscZinger> GetByLinkId(TransactionManager transactionManager, System.Int32 _linkId, int start, int pageLength)
		{
			int count = -1;
			return GetByLinkId(transactionManager, _linkId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DSC_ZINGERS_LINKS key.
		///		fkDscZingersLinks Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_linkId">Foreign key to LINKS</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.DscZinger objects.</returns>
		public TList<DscZinger> GetByLinkId(System.Int32 _linkId, int start, int pageLength)
		{
			int count =  -1;
			return GetByLinkId(null, _linkId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DSC_ZINGERS_LINKS key.
		///		fkDscZingersLinks Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_linkId">Foreign key to LINKS</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.DscZinger objects.</returns>
		public TList<DscZinger> GetByLinkId(System.Int32 _linkId, int start, int pageLength,out int count)
		{
			return GetByLinkId(null, _linkId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DSC_ZINGERS_LINKS key.
		///		FK_DSC_ZINGERS_LINKS Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_linkId">Foreign key to LINKS</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.DscZinger objects.</returns>
		public abstract TList<DscZinger> GetByLinkId(TransactionManager transactionManager, System.Int32 _linkId, int start, int pageLength, out int count);
		
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override BesAsm.MasterData.Entities.DscZinger Get(TransactionManager transactionManager, BesAsm.MasterData.Entities.DscZingerKey key, int start, int pageLength)
		{
			return GetByDscZingerId(transactionManager, key.DscZingerId, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_DSC_ZINGERS index.
		/// </summary>
		/// <param name="_dscZingerId">Primary key, DSC zinger ID</param>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.DscZinger"/> class.</returns>
		public BesAsm.MasterData.Entities.DscZinger GetByDscZingerId(System.Int32 _dscZingerId)
		{
			int count = -1;
			return GetByDscZingerId(null,_dscZingerId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_DSC_ZINGERS index.
		/// </summary>
		/// <param name="_dscZingerId">Primary key, DSC zinger ID</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.DscZinger"/> class.</returns>
		public BesAsm.MasterData.Entities.DscZinger GetByDscZingerId(System.Int32 _dscZingerId, int start, int pageLength)
		{
			int count = -1;
			return GetByDscZingerId(null, _dscZingerId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_DSC_ZINGERS index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_dscZingerId">Primary key, DSC zinger ID</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.DscZinger"/> class.</returns>
		public BesAsm.MasterData.Entities.DscZinger GetByDscZingerId(TransactionManager transactionManager, System.Int32 _dscZingerId)
		{
			int count = -1;
			return GetByDscZingerId(transactionManager, _dscZingerId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_DSC_ZINGERS index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_dscZingerId">Primary key, DSC zinger ID</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.DscZinger"/> class.</returns>
		public BesAsm.MasterData.Entities.DscZinger GetByDscZingerId(TransactionManager transactionManager, System.Int32 _dscZingerId, int start, int pageLength)
		{
			int count = -1;
			return GetByDscZingerId(transactionManager, _dscZingerId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_DSC_ZINGERS index.
		/// </summary>
		/// <param name="_dscZingerId">Primary key, DSC zinger ID</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.DscZinger"/> class.</returns>
		public BesAsm.MasterData.Entities.DscZinger GetByDscZingerId(System.Int32 _dscZingerId, int start, int pageLength, out int count)
		{
			return GetByDscZingerId(null, _dscZingerId, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_DSC_ZINGERS index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_dscZingerId">Primary key, DSC zinger ID</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.DscZinger"/> class.</returns>
		public abstract BesAsm.MasterData.Entities.DscZinger GetByDscZingerId(TransactionManager transactionManager, System.Int32 _dscZingerId, int start, int pageLength, out int count);
						
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key R144_ROWID_SDE_UK index.
		/// </summary>
		/// <param name="_objectid"></param>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.DscZinger"/> class.</returns>
		public BesAsm.MasterData.Entities.DscZinger GetByObjectid(System.Int32 _objectid)
		{
			int count = -1;
			return GetByObjectid(null,_objectid, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the R144_ROWID_SDE_UK index.
		/// </summary>
		/// <param name="_objectid"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.DscZinger"/> class.</returns>
		public BesAsm.MasterData.Entities.DscZinger GetByObjectid(System.Int32 _objectid, int start, int pageLength)
		{
			int count = -1;
			return GetByObjectid(null, _objectid, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the R144_ROWID_SDE_UK index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_objectid"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.DscZinger"/> class.</returns>
		public BesAsm.MasterData.Entities.DscZinger GetByObjectid(TransactionManager transactionManager, System.Int32 _objectid)
		{
			int count = -1;
			return GetByObjectid(transactionManager, _objectid, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the R144_ROWID_SDE_UK index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_objectid"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.DscZinger"/> class.</returns>
		public BesAsm.MasterData.Entities.DscZinger GetByObjectid(TransactionManager transactionManager, System.Int32 _objectid, int start, int pageLength)
		{
			int count = -1;
			return GetByObjectid(transactionManager, _objectid, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the R144_ROWID_SDE_UK index.
		/// </summary>
		/// <param name="_objectid"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.DscZinger"/> class.</returns>
		public BesAsm.MasterData.Entities.DscZinger GetByObjectid(System.Int32 _objectid, int start, int pageLength, out int count)
		{
			return GetByObjectid(null, _objectid, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the R144_ROWID_SDE_UK index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_objectid"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.DscZinger"/> class.</returns>
		public abstract BesAsm.MasterData.Entities.DscZinger GetByObjectid(TransactionManager transactionManager, System.Int32 _objectid, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a TList&lt;DscZinger&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="TList&lt;DscZinger&gt;"/></returns>
		public static TList<DscZinger> Fill(IDataReader reader, TList<DscZinger> rows, int start, int pageLength)
		{
			NetTiersProvider currentProvider = DataRepository.Provider;
            bool useEntityFactory = currentProvider.UseEntityFactory;
            bool enableEntityTracking = currentProvider.EnableEntityTracking;
            LoadPolicy currentLoadPolicy = currentProvider.CurrentLoadPolicy;
			Type entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;
			
			// advance to the starting row
			for (int i = 0; i < start; i++)
			{
				if (!reader.Read())
				return rows; // not enough rows, just return
			}
			for (int i = 0; i < pageLength; i++)
			{
				if (!reader.Read())
					break; // we are done
					
				string key = null;
				
				BesAsm.MasterData.Entities.DscZinger c = null;
				if (useEntityFactory)
				{
					key = new System.Text.StringBuilder("DscZinger")
					.Append("|").Append((System.Int32)reader[((int)DscZingerColumn.DscZingerId - 1)]).ToString();
					c = EntityManager.LocateOrCreate<DscZinger>(
					key.ToString(), // EntityTrackingKey
					"DscZinger",  //Creational Type
					entityCreationFactoryType,  //Factory used to create entity
					enableEntityTracking); // Track this entity?
				}
				else
				{
					c = new BesAsm.MasterData.Entities.DscZinger();
				}
				
				if (!enableEntityTracking ||
					c.EntityState == EntityState.Added ||
					(enableEntityTracking &&
					
						(
							(currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
							(currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
						)
					))
				{
					c.SuppressEntityEvents = true;
					c.Objectid = (System.Int32)reader[((int)DscZingerColumn.Objectid - 1)];
					c.DscZingerId = (System.Int32)reader[((int)DscZingerColumn.DscZingerId - 1)];
					c.OriginalDscZingerId = c.DscZingerId;
					c.DscId = (reader.IsDBNull(((int)DscZingerColumn.DscId - 1)))?null:(System.Int32?)reader[((int)DscZingerColumn.DscId - 1)];
					c.LinkId = (System.Int32)reader[((int)DscZingerColumn.LinkId - 1)];
					c.LinkType = (reader.IsDBNull(((int)DscZingerColumn.LinkType - 1)))?null:(System.String)reader[((int)DscZingerColumn.LinkType - 1)];
					c.Shape = (reader.IsDBNull(((int)DscZingerColumn.Shape - 1)))?null:(System.Object)reader[((int)DscZingerColumn.Shape - 1)];
					c.EntityTrackingKey = key;
					c.AcceptChanges();
					c.SuppressEntityEvents = false;
				}
				rows.Add(c);
			}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="BesAsm.MasterData.Entities.DscZinger"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.DscZinger"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, BesAsm.MasterData.Entities.DscZinger entity)
		{
			if (!reader.Read()) return;
			
			entity.Objectid = (System.Int32)reader[((int)DscZingerColumn.Objectid - 1)];
			entity.DscZingerId = (System.Int32)reader[((int)DscZingerColumn.DscZingerId - 1)];
			entity.OriginalDscZingerId = (System.Int32)reader["dsc_zinger_id"];
			entity.DscId = (reader.IsDBNull(((int)DscZingerColumn.DscId - 1)))?null:(System.Int32?)reader[((int)DscZingerColumn.DscId - 1)];
			entity.LinkId = (System.Int32)reader[((int)DscZingerColumn.LinkId - 1)];
			entity.LinkType = (reader.IsDBNull(((int)DscZingerColumn.LinkType - 1)))?null:(System.String)reader[((int)DscZingerColumn.LinkType - 1)];
			entity.Shape = (reader.IsDBNull(((int)DscZingerColumn.Shape - 1)))?null:(System.Object)reader[((int)DscZingerColumn.Shape - 1)];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="BesAsm.MasterData.Entities.DscZinger"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.DscZinger"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, BesAsm.MasterData.Entities.DscZinger entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.Objectid = (System.Int32)dataRow["OBJECTID"];
			entity.DscZingerId = (System.Int32)dataRow["dsc_zinger_id"];
			entity.OriginalDscZingerId = (System.Int32)dataRow["dsc_zinger_id"];
			entity.DscId = Convert.IsDBNull(dataRow["dsc_id"]) ? null : (System.Int32?)dataRow["dsc_id"];
			entity.LinkId = (System.Int32)dataRow["link_id"];
			entity.LinkType = Convert.IsDBNull(dataRow["LinkType"]) ? null : (System.String)dataRow["LinkType"];
			entity.Shape = Convert.IsDBNull(dataRow["SHAPE"]) ? null : (System.Object)dataRow["SHAPE"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.DscZinger"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">BesAsm.MasterData.Entities.DscZinger Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		public override void DeepLoad(TransactionManager transactionManager, BesAsm.MasterData.Entities.DscZinger entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;

			#region DscIdSource	
			if (CanDeepLoad(entity, "Dsc|DscIdSource", deepLoadType, innerList) 
				&& entity.DscIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = (entity.DscId ?? (int)0);
				Dsc tmpEntity = EntityManager.LocateEntity<Dsc>(EntityLocator.ConstructKeyFromPkItems(typeof(Dsc), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.DscIdSource = tmpEntity;
				else
					entity.DscIdSource = DataRepository.DscProvider.GetByDscId(transactionManager, (entity.DscId ?? (int)0));		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'DscIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.DscIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.DscProvider.DeepLoad(transactionManager, entity.DscIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion DscIdSource

			#region LinkIdSource	
			if (CanDeepLoad(entity, "Link|LinkIdSource", deepLoadType, innerList) 
				&& entity.LinkIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.LinkId;
				Link tmpEntity = EntityManager.LocateEntity<Link>(EntityLocator.ConstructKeyFromPkItems(typeof(Link), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.LinkIdSource = tmpEntity;
				else
					entity.LinkIdSource = DataRepository.LinkProvider.GetByLinkId(transactionManager, entity.LinkId);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'LinkIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.LinkIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.LinkProvider.DeepLoad(transactionManager, entity.LinkIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion LinkIdSource
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the BesAsm.MasterData.Entities.DscZinger object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">BesAsm.MasterData.Entities.DscZinger instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">BesAsm.MasterData.Entities.DscZinger Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		public override bool DeepSave(TransactionManager transactionManager, BesAsm.MasterData.Entities.DscZinger entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			
			#region DscIdSource
			if (CanDeepSave(entity, "Dsc|DscIdSource", deepSaveType, innerList) 
				&& entity.DscIdSource != null)
			{
				DataRepository.DscProvider.Save(transactionManager, entity.DscIdSource);
				entity.DscId = entity.DscIdSource.DscId;
			}
			#endregion 
			
			#region LinkIdSource
			if (CanDeepSave(entity, "Link|LinkIdSource", deepSaveType, innerList) 
				&& entity.LinkIdSource != null)
			{
				DataRepository.LinkProvider.Save(transactionManager, entity.LinkIdSource);
				entity.LinkId = entity.LinkIdSource.LinkId;
			}
			#endregion 
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region DscZingerChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>BesAsm.MasterData.Entities.DscZinger</c>
	///</summary>
	public enum DscZingerChildEntityTypes
	{
		
		///<summary>
		/// Composite Property for <c>Dsc</c> at DscIdSource
		///</summary>
		[ChildEntityType(typeof(Dsc))]
		Dsc,
			
		///<summary>
		/// Composite Property for <c>Link</c> at LinkIdSource
		///</summary>
		[ChildEntityType(typeof(Link))]
		Link,
		}
	
	#endregion DscZingerChildEntityTypes
	
	#region DscZingerFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;DscZingerColumn&gt;"/> class
	/// that is used exclusively with a <see cref="DscZinger"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class DscZingerFilterBuilder : SqlFilterBuilder<DscZingerColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the DscZingerFilterBuilder class.
		/// </summary>
		public DscZingerFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the DscZingerFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public DscZingerFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the DscZingerFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public DscZingerFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion DscZingerFilterBuilder
	
	#region DscZingerParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;DscZingerColumn&gt;"/> class
	/// that is used exclusively with a <see cref="DscZinger"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class DscZingerParameterBuilder : ParameterizedSqlFilterBuilder<DscZingerColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the DscZingerParameterBuilder class.
		/// </summary>
		public DscZingerParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the DscZingerParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public DscZingerParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the DscZingerParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public DscZingerParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion DscZingerParameterBuilder
	
	#region DscZingerSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;DscZingerColumn&gt;"/> class
	/// that is used exclusively with a <see cref="DscZinger"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class DscZingerSortBuilder : SqlSortBuilder<DscZingerColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the DscZingerSqlSortBuilder class.
		/// </summary>
		public DscZingerSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion DscZingerSortBuilder
	
} // end namespace
